package Exam1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Mainone {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<String> strList = new ArrayList<String>();
		while (scan.hasNext()) {
			String s = scan.next();
			s = s.trim();
			if (s.equals("end"))
				break;
			if (s.length() != 18)
				continue;
			else {
				strList.add(s);
			}
		}
		int i=strList.size();
		System.out.println(i);
		String[] str = new String[i];
		for (int j = 0; j <i ; j++) {
			str[j] = strList.get(j);
		}
		for (int j2 = str.length - 1; j2 >= 0; j2--) {
			System.out.println(str[j2]);
		}
		String a = scan.next();
		String b = scan.next();
		for (int j = str.length - 1; j >= 0; j--) {
			String s = strList.get(j).substring(6, 14);
			if (s.compareTo(a) < 0 || s.compareTo(b) > 0) {
				strList.remove(j);
			}
		}
		String[] s1 = new String[strList.size()];
		for (int k = 0; k < strList.size(); k++) {
			s1[k] = strList.get(strList.size() - k - 1).substring(6, 14);
		}
		System.out.println(Arrays.toString(s1));
		scan.close();
	}
}
